﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;

namespace Mole
{
    class FileID
    {
        public static String ScanFile(String filepath)
        {
            String value = String.Empty;

            try
            {
                String appDir = Application.StartupPath;

                //Start file.exe
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = appDir + "\\Dependencies\\" + "file.exe";
                startInfo.Arguments = String.Format("{0} \"{1}\"", "-b -N -m magic", filepath);
                startInfo.WorkingDirectory = appDir + "\\Dependencies";
                startInfo.RedirectStandardOutput = true;
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                startInfo.CreateNoWindow = true;
                startInfo.UseShellExecute = false;
                startInfo.ErrorDialog = false;

                using (Process processRun = new Process())
                {
                    processRun.StartInfo = startInfo;
                    processRun.Start();

                    value = processRun.StandardOutput.ReadToEnd();

                    processRun.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                value = ex.Message;
            }

            return value;
        }
    }
}
